import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';

export type TableListItem = {
  id;
  type;
  cautionTime;
  count;
  solveTime;
  status;
};

export const typeObj = {
  1: '到期出库',
  2: '到期归还',
};
export const statusObj = {
  3: '未处理',
  4: '已处理',
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    title: '提醒类型',
    field: 'type',
    formatter: ({ cellValue }) => {
      return typeObj[cellValue];
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: Object.values(typeObj).map((item, index) => ({
          label: item,
          value: Object.keys(typeObj)[index],
        })),
      },
    },
  },
  {
    title: '到期时间',
    field: 'cautionTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD') : '-';
    },
    searchField: 'cautionTimeBtw',
    formItemProps: {
      component: 'RangePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
      },
    },
  },
  {
    title: '数量',
    field: 'count',
    hideInSearch: true,
  },
  {
    title: '处理时间',
    field: 'solveTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    hideInSearch: true,
  },
  {
    title: '状态',
    field: 'status',
    formatter: ({ cellValue }) => {
      return statusObj[cellValue];
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: Object.values(statusObj).map((item, index) => ({
          label: item,
          value: Object.keys(statusObj)[index],
        })),
      },
      defaultValue: '3',
    },
  },
];
